package com.huobao.shangjia_version.activitys;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huobao.yunying.base.HuobaoBaseActivity;
import com.huobao.yunying.https.Http;
import com.huobao.yunying.https.HttpListener;
import com.huobao.yunying.https.HttpUtil;
import com.huobao.zhangying.R;

import org.xutils.view.annotation.ViewInject;

import java.util.Map;

/**
 * Created by Administrator on 2016/8/18.
 */
public class Act_Renzheng_List extends HuobaoBaseActivity implements View.OnClickListener {
	@ViewInject(R.id.view_geren)
	private View view_geren;
	@ViewInject(R.id.view_qiye)
	private View view_qiye;
	@ViewInject(R.id.tv_geren_status)
	private TextView tv_geren_status;
	@ViewInject(R.id.tv_qiye_status)
	private TextView tv_qiye_status;

	@Override
	protected int getContentView() {
		return R.layout.layout_renzheng_list;
	}

	@Override
	protected String getTitleText() {
		return "实名认证";
	}

	@Override
	protected void init() {
		view_geren.setOnClickListener(this);
		view_qiye.setOnClickListener(this);
		getStatus();
	}

	private int toexamine, examine;

	private void getStatus() {
		Map<String, String> map = HttpUtil.getParams("app", "approve");
		Http.getInstant().sendRequest(this, map, new HttpListener() {
			@Override
			public void onHttpSuccess(String result) {
				JSONObject jsonObject = JSON.parseObject(result);
				jsonObject = jsonObject.getJSONObject("retval");
				toexamine = jsonObject.getIntValue("toexamine");//个人实名认证状态(0审核中 1审核通过 2重新认证)
				examine = jsonObject.getIntValue("examine");//企业实名认证状态(0审核中 1审核通过 2重新认证)
				tv_geren_status.setText(jsonObject.getString("toexamine_text"));
				tv_qiye_status.setText(jsonObject.getString("examine_text"));
			}

			@Override
			public void onHttpError(String error) {

			}
		});
	}


	@Override
	public void onClick(View view) {
		Intent intent = new Intent();
		switch (view.getId()) {
			case R.id.view_qiye:
				if (examine == 0 || examine == 1) {
					intent.setClass(context, Act_See_Qiye_Renzheng.class);
					startActivity(intent);
				} else {
					intent.setClass(context, Act_Renzheng_Qiye.class);
					intent.putExtra("status", examine);
					startActivityForResult(intent,1);
				}
				break;
			case R.id.view_geren:
				if (toexamine == 0 || toexamine == 1) {
					intent.setClass(context, Act_See_Geren_Renzheng.class);
					startActivity(intent);
				} else {
					intent.setClass(context, Act_Renzheng_Geren.class);
					intent.putExtra("status", toexamine);
					startActivityForResult(intent,1);
				}
				break;
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if(resultCode == RESULT_OK){
			getStatus();
		}
	}
}
